package com.eshop.modules.shop.service.impl;

import java.io.IOException;
import java.util.Iterator;
import com.eshop.utils.FileUtil;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import java.util.List;
import com.github.pagehelper.PageInfo;
import com.eshop.modules.shop.service.dto.AppVersionDto;
import com.eshop.domain.PageResult;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.shop.service.dto.AppVersionQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.shop.service.AppVersionService;
import com.eshop.modules.shop.domain.AppVersion;
import com.eshop.modules.shop.service.mapper.AppVersionMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class AppVersionServiceImpl extends BaseServiceImpl<AppVersionMapper, AppVersion> implements AppVersionService
{
    private final IGenerator generator;
    
    public PageResult<AppVersionDto> queryAll(final AppVersionQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<AppVersion> page = (PageInfo<AppVersion>)new PageInfo((List)this.queryAll(criteria));
        return (PageResult<AppVersionDto>)this.generator.convertPageInfo((PageInfo)page, (Class)AppVersionDto.class);
    }
    
    public List<AppVersion> queryAll(final AppVersionQueryCriteria criteria) {
        return (List<AppVersion>)(this.baseMapper).selectList((Wrapper)QueryHelpPlus.getPredicate((Object)AppVersion.class, (Object)criteria));
    }
    
    public void download(final List<AppVersionDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final AppVersionDto yxAppVersion : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put(" isDel", yxAppVersion.getIsDel());
            map.put("更新时间", yxAppVersion.getCreateTime());
            map.put(" updateTime", yxAppVersion.getUpdateTime());
            map.put("版本code", yxAppVersion.getVersionCode());
            map.put("版本名称", yxAppVersion.getVersionName());
            map.put("版本描述", yxAppVersion.getVersionInfo());
            map.put("安卓下载链接", yxAppVersion.getAndroidUrl());
            map.put("是否强制升级", yxAppVersion.getForceUpdate());
            map.put("ios store应用商店链接", yxAppVersion.getIosUrl());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public AppVersionServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
